package com.example.controller;

import com.example.dao.impl.UserDaoimpl;
import com.example.entity.User;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.util.ArrayList;

@WebServlet("/collect")
public class CollectServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        UserDaoimpl userDaoimpl = new UserDaoimpl();
        User user = (User) req.getSession().getAttribute("user");
        if (user != null){
            ArrayList<Integer> collect = userDaoimpl.findCollectByUserID(String.valueOf(user.getUserId()));
            req.getSession().setAttribute("collect", collect);
            req.getRequestDispatcher("/collect.jsp").forward(req,resp);
        }
    }
}
